﻿//-----------------------------------------------------------------------
// <copyright file="DriverInfoForm.cs" company="AoTaiKe">
//     Custom company copyright tag.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Text;
using DevExpress.XtraEditors;
using System.Drawing;
using System.Windows.Forms;

namespace TaxiDispatchClient
{
    /// <summary>
    /// 驾驶员信息form
    /// </summary>
    public partial class DriverInfoForm : XtraForm
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DriverInfoForm() 
        { 
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void DriverInfoForm_Load(object sender, EventArgs e)
        {
            try
            {
                string strWhere = "t.State='0'";                
            
                DataSet ds = MainForm.PositionService.DriverGetList(strWhere);
                gridControl1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex, true);
            }
        }

        /// <summary>
        /// grid双击事件
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Yes;
            Close();
        } 

        /// <summary>
        /// 查询按钮点击事件
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void simpleButton_select_Click(object sender, EventArgs e)
        {
            if (radioGroup_type.SelectedIndex == -1)
            {
                XtraMessageBox.Show("请选择查询类型");
                return;
            }
            StringBuilder strSql = new StringBuilder();
            string strType = radioGroup_type.Properties.Items[radioGroup_type.SelectedIndex].Value.ToString();
            string strValue = textEdit_String.Text.Trim();
            strSql.Append("State='0' ");
            if (strValue!="")
            {
                strSql.Append(" and ");
                strSql.Append(strType);
                strSql.Append(" like '%");
                strSql.Append(strValue);
                strSql.Append("%' ");                
            }
            if (MainForm.MyUserInfo.CompanyName != Common.ConstParameters.MainCompanyName)
            {
                if (strSql.ToString()!="")
                {
                    strSql.Append(" and ");
                }
                strSql.Append("CompanyName ='");
                strSql.Append(MainForm.MyUserInfo.CompanyName);
                strSql.Append("' ");
            }
             
            try
            {
                DataSet ds = MainForm.PositionService.DriverGetList( strSql.ToString());
                gridControl1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex, true);
            }
        }

        /// <summary>
        /// 清空按钮点击事件
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void simpleButton_Clear_Click(object sender, EventArgs e)
        {
            textEdit_String.Text = string.Empty;
            try
            {
                DataSet ds = MainForm.PositionService.DriverGetList(string.Empty);
                gridControl1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Common.CommonRoutine.HandlingExceptions(ex, true);
            }
        }


        Point _mouseOff;
        bool _leftFlag;
        private void Taxi_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mouseOff = new Point(-e.X, -e.Y);
                _leftFlag = true;
            }
        }

        private void Taxi_MouseMove(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(_mouseOff.X, _mouseOff.Y);
                Location = mouseSet;
            }
        }

        private void Taxi_MouseUp(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                _leftFlag = false;
            }
        }

        private void pictureEdit_exit_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexit;
            Cursor = Cursors.Hand;
        }

        private void pictureEdit_exit_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexitPressDown;

            Cursor = Cursors.Arrow;

        }

        private void pictureEdit_exit_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void btn_MouseHover(object sender, EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void Form_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
        }



    }
}